<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ZodiacSign;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Models\Menu;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ZodiacSignController extends AdminController
{
    protected function grid()
    {
        return Grid::make(new ZodiacSign(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type')->display(function ($type) {
                return $this->getTypeNameAttribute($type);
            });
            $grid->column('title');
           // $grid->column('avatar')->image();
           $grid->column('avatar')->display(function ($avatar) {
                return $avatar ? '<img src="' . $avatar . '" style="width:50px;height:50px;"/>' : 'No image';
            });
            $grid->column('tags')->display(function ($tags) {
                return implode(', ', $tags);
            });
            //$grid->column('content');
            $grid->column('in_sign')->sortable()->display(function ($inSign) {
                return $this->getZodiacSignNameAttribute($inSign);
            });
            $grid->column('relation_id')->sortable()->display(function ($inSign) {
                return $this->getRelationTypeNameAttribute($inSign);
            });
            //$grid->column('tip');
            $grid->column('tags_color');
            $grid->column('tags_bg_color');
           // $grid->column('created_at');
            //$grid->column('updated_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('type');
                $filter->like('title');
                $filter->equal('in_sign');
                $filter->equal('relation_id');
            });
            
           $grid->disableViewButton();
        });
    }

    protected function form()
    {
        return Form::make(new ZodiacSign(), function (Form $form) {
            $form->display('id');
            $form->select('type')->options($this->getTypeOptions());
            $form->text('title');
            //$form->image('avatar')->url('files/uploads')->uniqueName()->autoUpload();
            $form->select('avatar')->options($this->getAvatarOptions())->required(); //临时地址操作方式
            $form->list('tags');
            $form->textarea('content');
            $form->select('in_sign')->options($this->getZodiacSigns())->required();
            $form->select('relation_id')->options($this->getRelationTypes())->required();
            $form->text('tip');
            $form->color('tags_color');
            $form->color('tags_bg_color');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
    
     protected function detail($id)
    {
        return Show::make($id, new ZodiacSign(), function (Show $show) {
            $show->field('id');
            $show->field('in_sign')->as(function ($inSign) {
                return $this->getZodiacSignNameAttribute($inSign);
            });
            $show->field('title');
            $show->field('tags')->as(function ($tags) {
                return implode(', ',$tags);
            });
            $show->field('content');
            $show->field('relation_id');
            $show->field('tip');
            $show->field('tags_color');
            $show->field('tags_bg_color');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }
    
    private function getZodiacSigns()
    {
        return [
            1 => '白羊座',
            2 => '金牛座',
            3 => '双子座',
            4 => '巨蟹座',
            5 => '狮子座',
            6 => '处女座',
            7 => '天秤座',
            8 => '天蝎座',
            9 => '射手座',
            10 => '摩羯座',
            11 => '水瓶座',
            12 => '双鱼座'
        ];
    }

   
     private function getRelationTypes()
    {
        return [
            0 => '全部',
            1 => '自己',
            2 => '恋人',
            3 => '朋友',
            4 => '同事',
            5 => '亲人',
            6 => '老板',
            7 => '前任',
            8 => '男生',
            9 => '女生'
        ];
    }
    
    private function getTypeOptions()
    {
        return [
            'overall' => '总体分析',
            'relation' => '关系分析'
        ];
    }
    private function getAvatarOptions()
    {
       return [
            'https://img1.lanmeishuo.com/2024/06/14/0/ad777d3053cd13bd63a6690b11b40cd3.png' => '亲人',
            'https://img1.lanmeishuo.com/2024/06/14/0/27531e5e568b5df1fdb899c43caecfb3.png' => '同事',
            'https://img1.lanmeishuo.com/2024/06/14/0/c91d68acdf03c45bf5f58f00239a6227.png' => '朋友',
            'https://img1.lanmeishuo.com/2024/06/14/0/96af5657d935c1c14f2e660131ab1755.png' => '恋人',
            'https://img1.lanmeishuo.com/2024/06/14/0/3bfb3306cd6b511ef439074ecf14966d.png' => '女生',
            'https://img1.lanmeishuo.com/2024/06/13/0/1b7c7664299d948f70a28cdaed345faf.png' => '男生',
        ];
    }
}
